﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BG.Web.Admin.Role.Default" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="Stylesheet" href="../resources/Kwan.icon.css" />
</head>
<body>
    <script type="text/javascript" src="../Kwan.Base.js"></script>
    <script type="text/javascript" src="Kwan.Role.js"></script>
    <form id="Form2" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="Role" />

        <ext:Store runat="server" ID="PermitDS">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="Value" />
                        <ext:RecordField Name="Text" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>

        <ext:Store ID="Store1" runat="server" OnRefreshData="RefreshDS" RemoteSort="True">
            <Proxy>
                <ext:PageProxy />
            </Proxy>
            <Reader>
                <ext:JsonReader IDProperty="EntityID">
                    <Fields>
                        <ext:RecordField Name="EntityID" />
						<ext:RecordField Name="NameCN" />
						<ext:RecordField Name="NameEN" /> 
                        <ext:RecordField Name="Memo" />
                        <ext:RecordField Name="Enable" />           
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <AutoLoadParams>
                <ext:Parameter Name="start" Value="0" Mode="Raw" />
                <ext:Parameter Name="limit" Value="15" Mode="Raw"/>
            </AutoLoadParams>
            <SortInfo Field="EntityID" Direction="DESC" />
        </ext:Store>
        <ext:Viewport runat="server" Layout="Column">
        <Items>
            <%--设置角色--%>
            <ext:GridPanel ID="GridPanel1" runat="server" ColumnWidth=".5" StoreID="Store1" ColumnLines="True" AutoExpandColumn="NameCN" Header="False" Frame="true" Height="500">
            <TopBar>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:Label runat="server" Html="<font color='red'>角色处于启用状态时，用户才能才能访问及操作相应页面</font>" Icon="Information" />
                        <ext:ToolbarFill />
                        <ext:Button ID="BtnAddInfo" runat="server" Text="添加" Icon="Add">
                            <DirectEvents>
                                <Click OnEvent="BtnAddInfo_Click" />
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button ID="BtnDelRole" runat="server" Text="删除" Icon="Delete">
                            <Listeners>
                                <Click Handler="Kwan.CheckDelete(#{GridPanel1}.getRowsValues({selectedOnly:true}));" />
                            </Listeners>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="BtnChangeEnable" runat="server" Text="启用" Icon="ArrowSwitchBlueGreen">
                            <Menu>
                                <ext:Menu ID="Menu1" runat="server">
                                    <Items>
                                        <ext:MenuItem ID="Enable_True" runat="server" Text="启用" Icon="BulletTick" />
                                        <ext:MenuItem ID="Enable_Flase" runat="server" Text="禁用" Icon="BulletCross" />
                                    </Items>
                                    <Listeners>
                                        <ItemClick Handler="Role.ChangeState(Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly:true})),menuItem.id);" />
                                    </Listeners>
                                </ext:Menu>
                            </Menu>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <ColumnModel runat="server">
			    <Columns>
                    <ext:RowNumbererColumn />
					<ext:Column ColumnId="NameCN" Header="角色名称" DataIndex="NameCN" />
                    <ext:Column Header="代码" DataIndex="NameEN" Width="100" />
                    <ext:Column Header="角色备注" DataIndex="Memo" Width="80" />
                    <ext:CommandColumn Header="启用" DataIndex="Enable" Width="40">
                        <Commands>
                            <ext:GridCommand CommandName="Enable" />
                        </Commands>
                        <PrepareToolbar Fn="Kwan.prepareBit" />
                    </ext:CommandColumn>
                    <%--<ext:CommandColumn Width="55" Hideable="false">
                        <Commands>
                            <ext:GridCommand CommandName="Delete" Icon="Delete" Text="删除" ToolTip-Text="删除该条记录" />
                        </Commands>
                    </ext:CommandColumn>--%>
			    </Columns>
            </ColumnModel>
            <SelectionModel>
               <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
            </SelectionModel>
            <LoadMask ShowMask="true" />
            <SaveMask ShowMask="true" />
            <Listeners>
                <Command Handler="Kwan.CellCommand(this, record, command, rowIndex)" />
                <RowClick Handler="Kwan.RoleGPClick(this.store.getAt(rowIndex).data.EntityID)" />
                <RowDblClick Handler="Kwan.CellCommand(this, this.store.getAt(rowIndex), 'Edit', rowIndex)" />
            </Listeners>
            </ext:GridPanel>
            <ext:Panel runat="server" Header="false" ColumnWidth=".5" Height="800" Layout="Row">
            <Items>
            <ext:TreePanel ID="ModuleTree" RowHeight=".5" UseArrows="true" AutoScroll="true" Animate="true" EnableDD="true" ContainerScroll="true" Border="false" Title="功能菜单" RootVisible="false" runat="server" Disabled="True">
                <Root>
                    <ext:AsyncTreeNode Text="Examples" NodeID="root"/>
                </Root>
                <Listeners>
                    <Render Handler="Kwan.nodeLoad(this.root)" />
                    <CheckChange Handler="Role.ChangeChecked(node.id, checked)" />
                    <Click Handler="Kwan.LoadPermit(node.id);" />
                </Listeners>
            </ext:TreePanel>
            <ext:GridPanel ID="RoleModuleGP" runat="server" RowHeight=".5" StoreID="PermitDS" ColumnLines="True" AutoExpandColumn="Text" Title="权限列表" Frame="true" Height="500" Disabled="True">
            <ColumnModel runat="server">
			    <Columns>
                    <ext:RowNumbererColumn />
					<ext:Column Header="权限名称" DataIndex="Text" />
			    </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:CheckboxSelectionModel ID="RoleModuleSM" runat="server">
                    <Listeners>
                        <BeforeRowSelect Handler="if(!record.data.Value){Role.ChangePermit(rowIndex, '1', eval('(' + ModuleTree.selectionModelField.value + ')').nodeID);}" />
                        <RowDeselect Handler="if(record.data.Value);Role.ChangePermit(rowIndex, '0', eval('(' + ModuleTree.selectionModelField.value + ')').nodeID);" />
                    </Listeners>
                </ext:CheckboxSelectionModel>
            </SelectionModel>
            <LoadMask ShowMask="true" />
            <SaveMask ShowMask="true" />
            </ext:GridPanel>
            </Items>
            </ext:Panel>
        </Items>
        </ext:Viewport>
        <ext:Window ID="EditWindow" runat="server" Icon="Group" Title="编辑数据" Width="400" Height="200" AutoShow="false" Modal="true" Collapsible="true" Maximizable="true" Hidden="true" Layout="Fit" LabelWidth="70" AnimateTarget="GridPanel1">
            <Items>
                <ext:FormPanel ID="EditForm" MonitorValid="true" runat="server" Header="false" Icon="ChartOrganisation" Padding="5" Layout="Form" LabelAlign="Right" LabelWidth="70" MonitorResize="true">
                    <Items>
                        <ext:Hidden ID="txtID" runat="server" />
						<ext:TextField ID="txtNameCN" FieldLabel="角色名称" AnchorHorizontal="98%" runat="server" AllowBlank="false" />
						<ext:TextField ID="txtNameEN" FieldLabel="代码" AnchorHorizontal="98%" runat="server" AllowBlank="false" />
                        <ext:TextField ID="txtMemo" FieldLabel="备注" AnchorHorizontal="98%" runat="server" />
                        <ext:RadioGroup ID="txtEnable" runat="server" ColumnsNumber="2" FieldLabel="选项" AnchorHorizontal="50%">
                            <Items>
                                <ext:Radio ID="txtEnable_True" BoxLabel="启用" runat="server" Checked="true"/>
                                <ext:Radio ID="txtEnable_False" BoxLabel="禁用" runat="server" />
                            </Items>
                        </ext:RadioGroup> 
                    </Items>
                    <Listeners>
                        <ClientValidation Handler="#{SaveButton}.setDisabled(!valid);" />
                    </Listeners>
                </ext:FormPanel>
            </Items>
            <Buttons>
                <ext:Button ID="SaveButton" runat="server" Text="保存" Icon="Disk">
                    <DirectEvents>
                        <Click OnEvent="SaveEditWindow" Failure="Ext.MessageBox.alert('系统提示', response.statusText);">
                            <EventMask Target="CustomTarget" CustomTarget="={#{EditWindow}.body}" ShowMask="True" />
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:Button ID="CancelButton" runat="server" Text="返回" Icon="Cancel">
                    <Listeners>
                        <Click Handler="#{EditWindow}.hide();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:Window>
    </form>
</body>
</html>